<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .carousel {
            width: 400px;
            margin: 10% auto;
            position: relative;
        }

        img {
            width: 400px;
            display: none;
        }

        img.active {
            display: block;
        }

        .bu {
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
        }

        .bu .active {
            background: #FFD700;
        }
    </style>
</head>
<body>
<div class="carousel">
    <img src="image/1.jpg" class="active">
    <img src="image/2.jpg">
    <img src="image/3.jpg">
    <div class="bu">
        <button class="active"></button>
        <button></button>
        <button></button>
    </div>
</div>

<script>
    let i = 0;
    const ims = document.querySelectorAll(".carousel img");
    const but = document.querySelectorAll(".bu button");
    const carousel = document.querySelector(".carousel");
    let timer = null;

    function change() {
        ims[i].classList.remove("active");
        but[i].classList.remove("active");
        i = (i + 1) % ims.length;
        ims[i].classList.add("active");
        but[i].classList.add("active");
    }

    for (let index = 0; index < but.length; index++) {
        but[index].onclick = function () {
            ims[i].classList.remove("active");
            but[i].classList.remove("active");
            i = index;
            ims[i].classList.add("active");
            but[i].classList.add("active");
        };
    }
    carousel.addEventListener("mouseenter", function () {
        if (!timer) {
            timer = setInterval(change, 3000);
        }
    });

    carousel.addEventListener("mouseleave", function () {
        clearInterval(timer);
        timer = null;
    });


</script>

</body>

</html>